package objects;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.util.ArrayList;

public class ConfiguracoesCliente implements Serializable{
	public enum Tela implements Serializable{
		CLIENTE,CHEFE
	}
private boolean isClient;
	private  Tela tela;
	private static transient ConfiguracoesCliente instace;
	private ArrayList<String> atendetes;
	private transient Path path;
private  String ipServidor;
private  String setor;
public String getIpServidor() {
	return ipServidor;
}
public void setIpServidor(String ipServidor) {
	this.ipServidor = ipServidor;
}
public String getSetor() {
	return setor;
}
public void setSetor(String setor) {
	this.setor = setor;
}
public Tela getTela() {
	return tela;
}
public void setTela(Tela tela) {
	this.tela = tela;
}
public ConfiguracoesCliente getInstace() {
	return instace;
}
public void setInstace(ConfiguracoesCliente instace) {
	this.instace = instace;
}
public ArrayList<String> getAtendetes() {
	return atendetes;
}
public void setAtendetes(ArrayList<String> atendetes) {
	this.atendetes = atendetes;
}
public boolean isClient() {
	return isClient;
}
public void setClient(boolean isClient) {
	this.isClient = isClient;
}
public Path getPath() {
	return path;
}
public void setPath(Path path) {
	this.path = path;
}
public static ConfiguracoesCliente getInstance() throws ClassNotFoundException, IOException{
	if(instace==null){
	instace = new ConfiguracoesCliente();
	}
	return instace;
}
private ConfiguracoesCliente() throws ClassNotFoundException, IOException{
	
		FileInputStream fis = new FileInputStream("config.ser");
		ObjectInputStream ois = new ObjectInputStream(fis);
		ConfiguracoesCliente c = (ConfiguracoesCliente)ois.readObject();
		ois.close();
		ConfiguracoesCliente.instace = c;
		
	
	
}






public ConfiguracoesCliente(String ipServidor, String setor, boolean isClient,
		ArrayList<String> atendetes,Path path) throws ClassNotFoundException, IOException {
	//this();
	this.ipServidor = ipServidor;
	this.setor = setor;
	this.isClient = isClient;
	this.atendetes = atendetes;
	this.path = path;
}
@Override
public boolean equals(Object arg0) {
	// TODO Auto-generated method stub
	return super.equals(arg0);
}
@Override
public int hashCode() {
	// TODO Auto-generated method stub
	return super.hashCode();
}
public static void substitui(String setor2, String ipConfig,
		boolean isClient, Path path, ArrayList<String> atendentes) throws IOException, ClassNotFoundException {
	// TODO Auto-generated method stub	
	FileOutputStream fs = new FileOutputStream("config.ser");
	ObjectOutputStream os = new ObjectOutputStream(fs);
	os.writeObject(new ConfiguracoesCliente(ipConfig,setor2,isClient,atendentes,path));
}
private void writeObject(ObjectOutputStream os){
	try{
		os.defaultWriteObject();
		os.writeObject(path.toString());	
	}catch(Exception e){
		e.printStackTrace();
	}
}
private void readObject(ObjectInputStream is){
	try{
		is.defaultReadObject();
		String pathString = (String)is.readObject(); 	
		path = Paths.get(pathString);
	}catch(Exception e){
		e.printStackTrace();
	}
}


}
